/*
 * htmlhelper.c
 *
 *  Created on: Jul 3, 2009
 *      Author: jacky
 */
#include <stdio.h>
/**
 *
 */
void htmlspecialchars(FILE *fp, const char *string)
{
	if (string)
	{
		while (*string != '\0')
		{
			switch (*string)
			{
			case '<':
				fprintf(fp, "&lt;");
				break;
			case '>':
				fprintf(fp, "&gt;");
				break;
			case '"':
				fprintf(fp, "&quot;");
				break;
			case '&':
				fprintf(fp, "&amp;");
				break;
			case '\'':
				fprintf(fp, "&apos;");
				break;
			/*case '\n':
				fprintf(fp,"&#%d;",*string);*/
			default:
				putc(*string,fp);
				break;
			}
			string++;
		}
	}
	else
	{
		fprintf(fp,"(null)");
	}
}
